
package examulator;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;


@WebServlet(name="SessionTrack", urlPatterns={"/SessionTrack"})
public class SessionTrack extends HttpServlet implements HttpSessionListener{
   
    static private int sessionCount;

    public void sessionCreated(HttpSessionEvent event){
    sessionCount++;
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        
        HttpSession session = request.getSession();
        PrintWriter out = response.getWriter();
        sessionCount++;

        try {
            out.println("Session count = "+ sessionCount);
        } catch (Exception e) {
        }
    }

    public void sessionDestroyed(HttpSessionEvent event){

    }
}

   